//
//  BaseTableViewController.swift
//  LBWeibo
//
//  Created by 李博 on 15/6/24.
//  Copyright © 2015年 libo. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController,VisitorLoginViewDelegate {

    /// 用户登录标记，Swift 2.0 现在设置初始数值不好使
    var userLogon = sharedUserAccount != nil
    
    //访客视图
    var visitorView: VisitorLoginView?
    
    override func loadView() {
        
        print("用户登录 \(userLogon)")
        userLogon ? super.loadView() : setupVisitorView()
        
    }
    
    private func setupVisitorView() {
        
        //替换根视图，系统默认在nav & tab之间建立一个视图
        visitorView = VisitorLoginView()
        visitorView?.delegate = self
        
        view = visitorView
        
        //添加导航栏登录注册按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorRegisterButtonClicked")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorLoginButtonClicked")
    }
    //MARK: - 访客视图协议方法
    func visitorRegisterButtonClicked() {
        print("注册")
    }
    
    ///登录
    func visitorLoginButtonClicked() {
        
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        
        presentViewController(nav, animated: true, completion: nil)        
    }
}
